//
//  YHTimeSubCell.m
//  ZhuKuang
//
//  Created by jjkj on 17/7/11.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "YHIolAlarmSubCell.h"

@interface YHIolAlarmSubCell()
{
    CABasicAnimation * _animation;
}
/**下边的线*/
@property (weak, nonatomic) IBOutlet UIView *bottomLine;
/**上边的线*/
@property (weak, nonatomic) IBOutlet UIView *topLine;
/**横向的线*/
@property (weak, nonatomic) IBOutlet UIView *hengLine;
/**cell分隔线*/
@property (weak, nonatomic) IBOutlet UIView *cellBoomLine;

/**油的名称*/
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
/**加油量*/
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
/**报警按钮*/
@property (weak, nonatomic) IBOutlet UIImageView *alarmBtn;
/**
 *  报警按钮点击事件
 */
-(IBAction)IolAlarmBtnAction:(UIButton *)sender;
@end

@implementation YHIolAlarmSubCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.topLine.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"vertical_point"]];
    self.bottomLine.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"vertical_point"]];
    self.hengLine.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"honrizontal_point"]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setSingleModel:(YHTimeSingleModel *)singleModel
{
    if ([singleModel.iol floatValue] != 0) {
        self.nameLabel.text = [NSString stringWithFormat:@"%.1fL",[singleModel.iol floatValue]];
    }else{
        self.nameLabel.text = @"0L";
    }
    self.numLabel.text = singleModel.iolnum;
    if ([singleModel.isException integerValue] == globalNum1) {
        [self.alarmBtn.layer addAnimation:[self opacityForever_Animation:0.7] forKey:[singleModel.iolnum stringByAppendingString:[@(self.section) stringValue]]];
    }else{
        [self.alarmBtn.layer removeAllAnimations];
    }
}

-(void)setIsLast:(BOOL)isLast
{
    _isLast = isLast;
    self.bottomLine.hidden = isLast;
    self.cellBoomLine.hidden = !isLast;
}

/**
 *  报警按钮点击事件
 */
-(IBAction)IolAlarmBtnAction:(UIButton *)sender
{
    if (self.singleClickBlock) {
        self.singleClickBlock();
    }
}
#pragma mark === 永久闪烁的动画 ======
-(CABasicAnimation *)opacityForever_Animation:(float)time
{
    if (!_animation) {
        _animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必须写opacity才行。
        _animation.fromValue = [NSNumber numberWithFloat:1.0f];
        _animation.toValue = [NSNumber numberWithFloat:0.0f];//这是透明度。
        _animation.autoreverses = YES;
        _animation.duration = time;
        _animation.repeatCount = MAXFLOAT;
        _animation.removedOnCompletion = NO;
        _animation.fillMode = kCAFillModeForwards;
        _animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];///没有的话是均匀的动画。
    }
    return _animation;
}
@end
